package testPaperJBFX;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import static testPaperJBFX.BasicReviewPaperActivity.InforBasicReview;


/**
 * 自定义fragment适配器
 * @author WGL
 *
 */
public class BasicReviewPaperFragmentAdapter extends FragmentPagerAdapter {

    private long flag = 0;
    private FragmentManager fm;

    public BasicReviewPaperFragmentAdapter(FragmentManager fm) {
        super(fm);
        this.fm = fm;
    }
    @Override
    public int getCount() {
        int sumCount = 0 ;
        if(InforBasicReview != null){
            sumCount = InforBasicReview.getPaperContent().size();
//            Log.e("===getCount==","======sumCount======"+sumCount);
        }
        return sumCount;
    }
    @Override
    public Fragment getItem(int position) {
        return BasicReviewPaperFragment.newInstance(position);
    }

//    @Override
//    public int getItemPosition(Object object) {
//        // 最简单解决 notifyDataSetChanged() 页面不刷新问题的方法
//        return POSITION_NONE;
//    }

//    @Override
//    public Object instantiateItem(ViewGroup container, int position) {
//        return (BasicReviewPaperFragment) super.instantiateItem(container, position);
//    }


    @Override
    public long getItemId(int position) {
        return position + flag;
    }

     public void paperHasSubmit(){
         flag = System.currentTimeMillis();
     }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Fragment fragment = (Fragment) super.instantiateItem(container,
                position);
        fm.beginTransaction().show(fragment).commit();
        return fragment;
        //return super.instantiateItem(container, position);
    }



    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // super.destroyItem(container, position, object);
        Fragment fragment = (Fragment) object;
        fm.beginTransaction().hide(fragment).commit();
    }
}
